package com.ethanzzh.ethanzzh_xdclass.controller;

import com.ethanzzh.ethanzzh_xdclass.model.pojo.Video;
import com.ethanzzh.ethanzzh_xdclass.service.VideoService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/video")
public class VideoController {

    @Autowired
    private VideoService videoService;

    @GetMapping("/page")
    public Object pageVideo(@RequestParam(value = "page", defaultValue = "1") int page,
                            @RequestParam(value = "size", defaultValue = "10") int size) {
        PageInfo pageInfo = PageHelper.startPage(page, size).doSelectPageInfo(
                () -> videoService.findAll()
        );

        return pageInfo;
    }


    @GetMapping("find_by_id")
    public Object findById(@RequestParam(value = "id", required = true) int id) {
        return videoService.findById(id);
    }

    @DeleteMapping("delete_by_id")
    public Integer delById(@RequestParam(value = "id", required = true) int id) {
        return videoService.delete(id);
    }

    @PostMapping("update_by_id")
    public Integer update(@RequestBody Video video) {

        return videoService.update(video);
    }

    @PostMapping("save")
    public Integer save(@RequestBody Video video) {
        return videoService.save(video);
    }
}

